package com.api.mapper;

import com.api.pojo.Task;
import com.api.pojo.UserTask;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserTaskMapper {

    @Insert("insert into user_task(uid, tid) value(#{uid}, #{tid})")
    void create(Integer uid, Integer tid);

    @Select("select * from user_task where uid = #{uid} and state = #{state} limit #{pageNo},#{pageSize}")
    List<UserTask> get(Integer uid, Integer state, Integer pageNo, Integer pageSize);

    @Select("select count(*) from user_task where uid = #{uid} and state = #{state} ")
    Integer countPage(Integer uid, Integer state);

    @Update("update user_task set state = #{state}, excuse = #{excuse}, time = now() where id = #{id}")
    void update(UserTask userTask);

    @Select("select ut.id, task.et from user_task ut join task on ut.tid = task.id where ut.uid = #{uid} and ut.state = 0")
    List<Task> getTask(Integer uid);

    @Select("select count(uid) from user_task where tid = #{tid} and state = #{state}")
    Integer count(Integer tid, Integer state);

    @Select("select * from user_task where tid = #{tid} and state = #{state} limit #{pageNo}, #{pageSize}")
    List<UserTask> getInfo(Integer tid, Integer state, Integer pageNo, Integer pageSize);

    @Select("select count(*) from user_task where tid = #{tid} and state = #{state}")
    Integer countInfo(Integer tid, Integer state);
}
